package com.ims.service.impl;

import com.ims.dao.DaoSupport;
import com.ims.entity.system.Role;
import com.ims.service.RoleService;
import com.ims.util.PageData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Resource(name = "daoSupport")
    private DaoSupport dao;


    @Override
    public List<Role> listAllERRoles() throws Exception {
        return (List<Role>) dao.findForList("RoleMapper.listAllERRoles", null);
    }


    @Override
    public List<Role> listAllRoles() throws Exception {
        return (List<Role>) dao.findForList("RoleMapper.listAllRoles", null);
    }


    @Override
    public void setAllRights(PageData pd) throws Exception {
        dao.update("RoleMapper.setAllRights", pd);

    }

    @Override
    public void add(PageData pd) throws Exception {
        dao.findForList("RoleMapper.insert", pd);
        /*for (int i=0; i < 5; i ++)
        {
            pd.put("ROLE_ID", UuidUtil.get32UUID());
            if (i == 3)
            {
                throw new Exception();
            }
            else{
                dao.findForList("RoleMapper.insert", pd);
            }

        }*/

    }

    @Override
    public List<PageData> listAllUByRid(PageData pd) throws Exception {
        return (List<PageData>) dao.findForList("RoleMapper.listAllUByRid", pd);
    }

    @Override
    public List<PageData> listAllAppUByRid(PageData pd) throws Exception {
        return (List<PageData>) dao.findForList("RoleMapper.listAllAppUByRid", pd);
    }

    @Override
    public List<Role> listAllRolesByPId(PageData pd) throws Exception {
        return (List<Role>) dao.findForList("RoleMapper.listAllRolesByPId", pd);
    }




    @Override
    public void deleteRoleById(String ROLE_ID) throws Exception {
        dao.delete("RoleMapper.deleteRoleById", ROLE_ID);
    }

    @Override
    public Role getRoleById(String roleId) throws Exception {
        return (Role) dao.findForObject("RoleMapper.getRoleById", roleId);
    }

    @Override
    public void updateRoleRights(Role role) throws Exception {
        dao.update("RoleMapper.updateRoleRights", role);
    }

    @Override
    public void updateQx(String msg, PageData pd) throws Exception {
        dao.update("RoleMapper."+msg, pd);
    }

    @Override
    public PageData findObjectById(PageData pd) throws Exception {
        return (PageData)dao.findForObject("RoleMapper.findObjectById", pd);
    }

    @Override
    public PageData edit(PageData pd) throws Exception {
        return (PageData)dao.findForObject("RoleMapper.edit", pd);
    }
}
